package core.layer
{
	import com.friendsofed.isometric.IsoWorld;
	
	import flash.display.Sprite;
	import flash.display.Stage;

	public class XStageLayer
	{
		private static var _instance : XStageLayer;
		
		private var _stage : Stage;
		
		private var _worldLayer : 		IsoWorld;
		private var _uiLayer	: 		XUILayer;
		private var _mouseLayer :		XMouseHandLayer;
		private var _popupLayer : 		XPopupLayer;
		
		public function XStageLayer( )
		{
			
		}
		
		public function init(stage : Stage):void
		{
			this._stage = stage;
			
			clear();
			
			_worldLayer =		new IsoWorld;
			_uiLayer = 			XUILayer.Instance;
			_mouseLayer = 	 	XMouseHandLayer.Instance;
			_popupLayer = 		XPopupLayer.Instance;
			
			stage.addChild(_worldLayer);
			stage.addChild(_uiLayer);
			stage.addChild(_mouseLayer);
			stage.addChild(_popupLayer);
		}
		
		public function get world() : IsoWorld
		{
			return _worldLayer;
		}
		
		public function get ui() : XUILayer
		{
			return _uiLayer;
		}
		
		public function get mouse() : XMouseHandLayer
		{
			return _mouseLayer;
		}
		
		public function get popup() : XPopupLayer
		{
			return _popupLayer;
		}
		
		public static function get Instance() : XStageLayer
		{
			if(!_instance)
			{
				_instance = new XStageLayer();
			}
			
			return _instance;
		}
		
		public function clear() : void
		{
			for(var i:int=_stage.numChildren-1;i>=0;i--)
			{
				_stage.removeChildAt(i);
			}
		}
	}
}